package com.leyou.controller;

import com.leyou.ResponseData;
import com.leyou.entity.SpecGroup;
import com.leyou.service.SpecGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/spec/group")
public class SpecGroupController {

    @Autowired
    private SpecGroupService specGroupService;

    @GetMapping("/{id}")
    public ResponseData getSpecGroups(@PathVariable Long cid) {
        try {
            if (cid > 0) {
                List<SpecGroup> specGroups = specGroupService.getSpecGroups(cid);
                return ResponseData.ok(specGroups);
            } else {
                return ResponseData.error(400, "cid,请求参数有误!", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseData.error(500, "服务器繁忙!", null);
    }
}
